// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Web.Mvc.Areas.HtAdmin.Controllers;

[MaMvc(controllerDescription: "系统设置", PCode = "HtAdmin_System")]
public class SysSettingController : HtAdminBaseController
{
    private readonly ILogger<UserController> _logger;
    private readonly IDataConfigService _dataConfigService;

    public SysSettingController(ILogger<UserController> logger
    , IDataConfigService dataConfigService)
    {
        _logger = logger;
        _dataConfigService = dataConfigService;
    }

    //[MaMenu(name: "设置页面", CreateDate = "2021-07-22")]
    //[MaPermission(name: "权限列表", actions: "Index,GetList")]
    public IActionResult Index()
    {
        return View();
    }

    /// <summary>
    /// 系统设置
    /// </summary>
    /// <returns></returns>
    [MaMenu(name: "系统设置", CreateDate = "2021-07-31")]
    [MaPermission(name: "系统设置", actions: "SystemSetting,ImgUpload,FileUpload")]
    [HttpGet]
    public async Task<IActionResult> SystemSetting()
    {
        var model = await _dataConfigService.GetSetting<SysSettingDto>(SysDataConfigKey.SysSetting);
        return View(model);
    }

    [HttpPost]
    public async Task<JsonResult> SystemSetting(SysSettingDto input)
    {
        await _dataConfigService.AddOrUpdateSetting(input, SysDataConfigKey.SysSetting);
        return Json("");
    }

    /// <summary>
    /// 图片上传
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    [MaPermission(name: "图片上传", actions: "ImgUpload")]
    [HttpPost]
    [IgnoreAntiforgeryToken]
    public async Task<JsonResult> ImgUpload(string type)
    {
        var uploadresult = await WebUpLoad.FileUpload(new WebUploadInput(FloderName: type));
        return Json(uploadresult.GetDefaultResult());
    }

    /// <summary>
    /// 文件上传
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    [MaPermission(name: "文件上传", actions: "FileUpload")]
    [HttpPost]
    [IgnoreAntiforgeryToken]
    public async Task<JsonResult> FileUpload(string type)
    {
        var uploadresult = await WebUpLoad.FileUpload(new WebUploadInput(FloderName: type));
        return Json(uploadresult.GetDefaultResult());
    }
}